package com.xinchuang.initializrdemo.utils;

import com.xinchuang.initializrdemo.entity.User;

import java.util.ArrayList;

public class DaoUtils {
    public static ArrayList<User> userList = new ArrayList();
    static {
        userList.add(new User("1", "大山", 21));
        userList.add(new User("2", "小美", 18));
        userList.add(new User("3", "丧彪", 22));
    }

    public static ArrayList<User> selectUserList() {
        return userList;
    }

    public static void insertUser(User user) {
        userList.add(user);
    }
    public static void deleteUser(String userId) {
        for (User user : userList) {
            if(user.getId().equals(userId)){
                userList.remove(user);
            }
        }
    }

    public static void updateUser(User userNew) {
        for (User user : userList) {
            if(user.getId().equals(userNew.getId())){
                userList.remove(user);
                userList.add(userNew);
            }
        }
    }
}
